package com.bot.backend.service.impl.pk;

import com.bot.backend.consumer.WebSocketServer;
import com.bot.backend.service.pk.ReceiveSnakeMoveService;
import com.bot.backend.utils.Game;
import org.springframework.stereotype.Service;

@Service
public class ReceiveSnakeMoveServiceImpl implements ReceiveSnakeMoveService {
    @Override
    public String receiveSnakeMove(Integer userId, Integer direction) {
        System.out.println("receive snake move：" + userId + " " + direction);
        if (WebSocketServer.users.get(userId) != null) {
            Game game = WebSocketServer.users.get(userId).game;
            if (game != null) {
                if (game.getPlayerA().getId().equals(userId)) {
                        game.setNextStepA(direction);
                } else if (game.getPlayerB().getId().equals(userId)) {
                        game.setNextStepB(direction);
                }
            }

    }
        return "snake move success";
    }
}
